<?
require_once("mvc/action/Action.php");
require_once("cms/download/om/DownloadRevisionPeer.php");
require_once("cms/core/om/BinaryFilePeer.php");

class EditAction extends Action {

    private $log;

    public function __construct() {
        $this->log =& LoggerManager::getLogger("EditAction");
    }

    public function execute(ActionConfig &$mapping, &$form, Request &$request, Response &$response) {

        if($form->getRevision()->getDownloadRevisionId() > 0) {

            $revision = DownloadRevisionPeer::retrieveByPk($form->getRevision()->getDownloadRevisionId());

            if(!is_null($revision)) {

                $revision->setDescription(null);
                $form->setPublicationDay($revision->getDownload()->getPublicationDate("d"));
                $form->setPublicationMonth($revision->getDownload()->getPublicationDate("m"));
                $form->setPublicationYear($revision->getDownload()->getPublicationDate("Y"));
                $form->setRevision($revision);

            } else {
                $this->log->error("No revision found with id {$form->getRevision()->getDownloadRevisionId()}.");
                $form->getRevision()->setDownloadRevisionId("");
            }

        } else {

            $form->setPublicationDay(date("d"));
            $form->setPublicationMonth(date("m"));
            $form->setPublicationYear(date("Y"));

        }

        return $mapping->findForward("success");

    }

}
?>